﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TraductorAVoz.ViewModel
{
   public class TraductorAVozViewModel:NotificationObject
    {

        private System.Windows.Threading.Dispatcher disp;

        public System.Windows.Threading.Dispatcher Disp
        {
            get { return disp; }
            set { disp = value; }
        }
        

        private BingTranslatorService traductor;

        private string textoOriginal;

        public string TextoOriginal
        {
            get { return textoOriginal; }
            set { textoOriginal = value;
      

             OnPropertyChanged(this);
          
            }
        }

        private string textoTraducido;

        public string TextoTraducido 
        {
            get { return textoTraducido; }
            set { textoTraducido = value;

            disp.BeginInvoke(new Action(() => {
                OnPropertyChanged(this);
            }));
            
            }
        }

        private ActionCommand traducirCommand;

        public ActionCommand TraducirCommand
        {
            get { return traducirCommand; }
            set { traducirCommand = value; }
        }
        

        public TraductorAVozViewModel() {
            configTraductor();
            TraducirCommand = new ActionCommand(new Action<string, string, string>(traductor.translate));
        }

        private void configTraductor()
        {
            traductor = new BingTranslatorService();
            traductor.TranslationReadyEvent += (s, e) =>
            {

                TextoTraducido = e.Result;
                
            };
        }
      
    }
}
